home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_mc.idb / usr / freeware / lib / mc / extfs / README.z / README
Encoding:
Text File  |  1998-10-28  |  7.7 KB  |  215 lines

  1.             Writing scripts for Midnight Commander's external vfs
  2.  
  3. IMPORTANT NOTE: extfs is not officialy released and fully bug free
  4. in 3.0! You have been warned. If you would really like to try it,
  5. you can (by typing make install.extfs in the vfs directory).
  6.  
  7. Starting with version 3.1, the Midnight Commander comes with so called
  8. extfs, which is one of the virtual filesystems. This system makes it
  9. possible to create new virtual filesystems for the GNU MC very easily.
  10.  
  11. Such work has two basic steps:
  12.  
  13. Editing $(libdir)/extfs/extfs.ini.
  14. Creating a shell script/program to handle requests.
  15. (Note: $(libdir) should be substituted for actual libdir path stored when
  16. configured or compiled, like /usr/local/lib/mc or /usr/lib/mc).
  17.  
  18. The first one is very easy:
  19. You assign a vfs prefix and vfs extensions to your vfs. Both will be used in
  20. vfs pseudoURL names, like if you assign prefix zip and extensions .zip,
  21. .ZIP, then URLs will look like
  22. zip:anypath/my.zip/some_path/in_the/archive
  23. Then you add a line to the end of the [extfs] section:
  24. prefix=space_separated_extensions
  25. e.g.
  26. zip=.zip .ZIP
  27.  
  28. The second one may require some your knowledge of shell/c programming:
  29. You have to create a program (with executable permissions) prefix in
  30. $(libdir)/extfs (in our example $(libdir)/extfs/zip).
  31.  
  32. * Commands that should be implemented by your shell script
  33. ----------------------------------------------------------
  34.  
  35. $libdir/extfs/prefix command [arguments]
  36.  
  37. * Command: list archivename
  38.  
  39. This command should list the complete archive content in the following format
  40. (a little modified ls -l listing):
  41.  
  42. AAAAAAA NNN OOOOOOOO GGGGGGGG SSSSSSSS DATETIME [PATH/]FILENAME [-> [PATH/]FILENAME[/]]]
  43.  
  44. where (things in [] are optional):
  45.  
  46. AAAAAAA  is the permission string like in ls -l
  47. NNN      is the number of links
  48. OOOOOOOO is the owner (either UID or name)
  49. GGGGGGGG is the group (either GID or name)
  50. SSSSSSSS is the file size
  51. FILENAME is the filename
  52. PATH     is the path from the archive's root without the leading slash (/)
  53. DATETIME has one of the following formats:
  54.         Mon DD hh:mm
  55.         Mon DD YYYY
  56.         Mon DD YYYY hh:mm
  57.         MM-DD-YY hh:mm
  58.  
  59.             where Mon is a three digit english month name, DD day
  60.             1-31, MM month 01-12, YY two digit year, YYYY four digit
  61.             year, hh hour and mm minute.
  62.  
  63. If the -> [PATH/]FILENAME part is present, it means:
  64.  
  65. If permissions start with an l (ell), then it is the name that symlink
  66. points to. (If this PATH starts with a MC vfs prefix, then it is a symlink
  67. somewhere to the other virtual filesystem (if you want to specify path from
  68. the local root, use local:/path_name instead of /path_name, since /path_name
  69. means from root of the archive listed).
  70. If permissions do not start with l, but number of links is greater than one,
  71. then it says that this file should be a hardlinked with the other file.
  72.  
  73.  
  74. * Command: copyout archivename storedfilename extractto
  75.  
  76. This should extract from archive archivename the file called
  77. storedfilename (possibly with path if not located in archive's root)
  78. to file extractto.
  79.  
  80. * Command: copyin archivename storedfilename sourcefile
  81.  
  82. This should add to the archivename the sourcefile with the name
  83. storedfilename inside the archive.  
  84.  
  85. Important note: archivename in the above examples may not have the
  86. extension you are expecting to have, like it may happen that
  87. archivename will be something like /tmp/f43513254 or just
  88. anything. Some archivers do not like it, so you'll have to find some
  89. workaround.
  90.  
  91. ---------------------------------------------------------
  92.  
  93. Don't forget to mark this file executable (chmod 755 ThisFile, for example)
  94.  
  95. This is a skeleton structure of the executable:
  96.  
  97. #!/bin/sh
  98.  
  99. # Command functions
  100. mcvfs_list ()
  101. # $1 is the archive name
  102. {
  103. # Apply a system command to obtain a list of filenames
  104. # For example 'zip -l $1'
  105. # Scan each line of the 'list' output, discarding unused information, and
  106. # constructing a printable line in a form, described above, that mc can use.
  107. # Exit
  108. }
  109.  
  110. mcvfs_copyout ()
  111. # $1 is the archive name
  112. # $2 is a name of a file within the archive
  113. # $3 is a name of a file within the system (to add from or extract to)
  114. {
  115. # Apply the system command used to extract one file from the archive
  116. # Exit
  117. }
  118.  
  119. mcvfs_copyin ()
  120. # $1 is the archive name
  121. # $2 is a name of a file within the archive
  122. # $3 is a name of a file within the system (to add from or extract to)
  123. {
  124. # Apply the system command used to add one file to the archive
  125. # Exit
  126. }
  127.  
  128. # Command line parser
  129. # $1 is the command
  130. # $2 is the archive name
  131. # $3 is a name of a file within the archive
  132. # $4 is a name of a file within the system (to add from or extract to)
  133. case "$1" in
  134.    list)    mcvfs_list $2;          exit $?;;
  135.    copyout) mcvfs_copyout $2 $3 $4; exit $?;;
  136.    copyin)  mcvfs_copyin $2 $3 $4;  exit $?;;
  137. esac
  138. # Show an error if this was called with some other command
  139. exit 1
  140.  
  141. ---------------------------------------------------------
  142.  
  143. In constructing these routines, errors will be made, and mc will not display
  144. a malformed printing line.  That can lead the programmer down many false
  145. trails in search of the bug.  Since this routine is an executable shell script
  146. it can be run from the command line independently of mc, and its output will
  147. show on the console or can be redirected to a file.
  148.  
  149. * Putting it to use
  150. ----------------------------------------------------------
  151. The file .mc.ext in a home directory, and in mc's user directory (commonly
  152. /usr/local/lib/mc), contains instructions for operations on files depending
  153. on filename extensions.  It is well documented in other files in this 
  154. distribution, so here are just a few notes specifically on use of the
  155. Virtual File System you just built.
  156.  
  157. There are entries in .mc.ext defining a few operations that can be done on a
  158. file from an mc panel.  Typically they are annotated with a hash mark and a
  159. file extension like this:
  160.  
  161. # zip
  162.  
  163. There must be a way to find the file by extension, so the next line does
  164. that.  In essence it says "identify the string ".zip" or (|) ".ZIP" at the
  165. end ($) of a filename": 
  166.  
  167. regex/\.(zip|ZIP)$
  168.  
  169. The operations themselves follow that. They must be indented by at least a
  170. space, and a tab works as well.  In particular, the Open operation will
  171. now use your new virtual file system by cd'ing to it like this:
  172.  
  173.    Open=%cd zip:%d/%p
  174.  
  175. This is the line used when a file is highlighted in a panel and the user
  176. presses <Enter> or <Return>.  The contents of the archive should show just
  177. as if they were in a real directory, and can be manipulated as such.
  178. The rest of the entry pertains to use of the F3 View key:
  179.  
  180.    View=%view{ascii} unzip -v %f
  181.  
  182. And perhaps an optional icon for X:
  183.  
  184.    Icon=zip.xpm
  185.  
  186. And perhaps an operation to extract the contents of the file, called from
  187. a menu selection:
  188.  
  189.    Extract=unzip %f '*'
  190.  
  191. This is just an example.  The current entry for .zip files has a menu selection
  192. of 'Unzip' which could be used in place of 'Extract'.  What goes here depends
  193. on what items you have in, or add to, the menu system, and that's another 
  194. subject.  The sum of this is the .mc.ext entry:
  195.  
  196. # zip
  197. regex/\.(zip|ZIP)$
  198.    Open=%cd zip:%d/%p
  199.    View=%view{ascii} unzip -v %f
  200.    Icon=zip.xpm
  201.    Extract=unzip %f '*'
  202.  
  203. Add an entry like this to the .mc.ext file in a user's home directory, If you
  204. want others to have it, add it to the mc.ext file in the mc system directory,
  205. often /usr/local/lib/mc/mc.ext.  Notice this file is not prepended with a dot.
  206.  
  207. Once all this is done, and things are in their proper places, exit mc if you
  208. were using it, and restart it so it picks up the new information.
  209.  
  210. That's all there is to it.  The hardest part is making a listing function
  211. that sorts the output of a system listing command and turns it into a form
  212. that mc can use.  Currently awk (or gawk) is used because nearly all systems
  213. have it. If another scripting language is available, like perl, that could
  214. also be used. 
  215.